<?php
namespace app\admin\controller;

use app\BaseController;
use think\facade\View;
use tool\Auth;
use think\facade\Route;
class Index extends BaseController
{
    public function index()
    {
        
        
        return View::fetch();
    }
    
    public function home()
    {
			\dump(\request()->server('PATH_INFO'));
       //   return View::fetch();
    }
   
   // 获取初始化数据
   public function getSystemInit(){
		 
 
       $homeInfo = [
           'title' => '首页',
           'href'  => (string) url('index/home'),
       ];
       $logoInfo = [
           'title' => '系统管理',
           'image' => '/static/common/images/logo.png',
       ];
       $menuInfo = $this->getMenuList();
       $systemInit = [
           'homeInfo' => $homeInfo,
           'logoInfo' => $logoInfo,
           'menuInfo' => $menuInfo,
       ];
       return json($systemInit);
   }
   
   // 获取菜单列表
   private function getMenuList(){
        $authModel = new Auth();
       $menuList = $authModel->getAuthMenu(session('admin_role_id'));
       $menuList = $this->buildMenuChild(-1, $menuList);
       return $menuList;
   }
   
   //递归获取子菜单
   private function buildMenuChild($pid, $menuList){
       $treeList = [];
       foreach ($menuList as $v) {
           if ($pid == $v['pid']) {
               $node = $v;
               $child = $this->buildMenuChild($v['id'], $menuList);
               if (!empty($child)) {
                   unset($child['id']);
                   unset($child['pid']);
                   $node['child'] = $child;
               }
               // todo 后续此处加上用户的权限判断
               $treeList[] = $node;
           }
       }
       return $treeList;
   }  
}
